package com.relax.join;

public class Demo {
    public void a(Thread thread) throws InterruptedException {
        System.out.println("a方法开始执行...");
        thread.start();
        thread.join();


        System.out.println("a方法执行完毕....");
    }

    public void b() throws InterruptedException {
        System.out.println("加塞方法开始执行...");
        Thread.sleep(3000);

        System.out.println("加塞方法执行完毕....");
    }


    public static void main(String[] args) {
        final Demo demo = new Demo();
        final Thread t1 = new Thread(new Runnable() {
            public void run() {
                try {
                    demo.b();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });


        new Thread(new Runnable() {
            public void run() {
                try {
                    demo.a(t1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
